package com.gec.anan.customer.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.gec.anan.common.constant.RedisConstant;
import com.gec.anan.common.login.AnanLogin;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.util.AuthContextHolder;
import com.gec.anan.customer.service.CustomerService;
import com.gec.anan.model.form.customer.UpdateWxPhoneForm;
import com.gec.anan.model.vo.customer.CustomerLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "客户API接口管理")
@RestController
@RequestMapping("/customer")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private CustomerService customerService;

    @Operation(summary = "小程序授权登陆")
    @GetMapping("/login/{code}")
    public Result<String> wxLogin(@PathVariable String code){
        //返回的是token
        return Result.ok(customerService.login(code));
    }


    @Operation(summary = "获取用户登陆信息")
    @GetMapping("/getCustomerLoginInfo")
    @AnanLogin
    public Result<CustomerLoginVo>  getCustomerLoginInfo(){
        Long customerId = AuthContextHolder.getUserId();
        CustomerLoginVo customerLoginVo = customerService.getCustomerLoginInfo(customerId);
        return Result.ok(customerLoginVo);
        //从threadlocal中获取用户的id（customerId）
    }

    @Operation(summary = "更新用户微信手机号")
    @AnanLogin
    @PostMapping("/updateWxPhone")
    public Result updateWxPhone(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
        updateWxPhoneForm.setCustomerId(AuthContextHolder.getUserId());
        //注销掉更新顾客手机号码的方法
//        customerService.updateWxPhoneNumber(updateWxPhoneForm);
        return Result.ok(true);
    }
}

